const base_url = "https://tea.qingnian8.com/api/bizhi"

export function request(option = {}){
	let {
		url,
		data = {},
		method = "GET",
		header = {}
	 } = option
	
	url = base_url + url
	header['access-key'] = "onlyloveting204"
	
	return new Promise((resolve,rejects) => {
		uni.request({
			url,
			data,
			method,
			header,
			success: (res)=>{
				if(res.data.errCode === 0){
					resolve(res.data)
				}else if(res.data.errCode === 400){
					uni.showModal({
						title:"错误信息",
						content:res.data.errMsg
					})
					rejects(res.data)
				}else{
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
					rejects(res.data)
				}
			},
			fail: (err)=>{
				rejects(err)
			}
		})
	})
}